﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Experiments.MichaelKappel.Net.Tilt.Axis
{
    public struct AxisDegreeInfo : IAxis
    {
        private Double _x;
        private Double _y;
        private Double _z;

        public AxisDegreeInfo(Double x, Double y, Double z)
        {
            _x = Wrap(x);
            _y = Wrap(y);
            _z = Wrap(z);
        }
        public Double X
        {
            get
            {
                return  _x;
            }
            set
            {
                _x = Wrap(value);
            }
        }
        public Double Y
        {
            get
            {
                return _y;
            }
            set
            {
                _y = Wrap(value);
            }
        }
        public Double Z
        {
            get
            {
                return _z;
            }
            set
            {
                _z = Wrap(value);
            }
        }
        /// <summary>
        /// Sets value between MIN and less then MAX
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static Double Wrap(Double arg)
        {
            Double result;
            if (arg < 0)
                result = 360 + arg;
            else if (arg >= 360)
                result = arg - 360;
            else
                result = arg;

            if (result < 0 || result >= 360)
                result = Wrap(result);

            return result;
        }
        public static AxisDegreeInfo ConvertToDegreeInfo(AxisInfo raw)
        {
            return new AxisDegreeInfo((raw.X + 2d) * 90d, (raw.Y + 2d) * 90d, (raw.Z + 2d) * 90d);
        }
    }
}
